package com.tinycloud.miracll.finance.service.impl;

import java.util.List;

import com.tinycloud.common.core.text.UUID;
import com.tinycloud.common.core.utils.DateUtils;
import com.tinycloud.common.core.utils.bean.BeanUtils;
import com.tinycloud.miracll.finance.domain.SapProductionOrder;
import com.tinycloud.miracll.finance.service.ISapProductionOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tinycloud.miracll.finance.mapper.SapProductOrderMapper;
import com.tinycloud.miracll.finance.domain.SapProductOrder;
import com.tinycloud.miracll.finance.service.ISapProductOrderService;

/**
 * SAP订单Service业务层处理
 * 
 * @author tiny
 * @date 2021-09-06
 */
@Service
public class SapProductOrderServiceImpl implements ISapProductOrderService 
{
    @Autowired
    private SapProductOrderMapper sapProductOrderMapper;

    @Autowired
    private ISapProductionOrderService sapProductionOrderService;


    /**
     * 新增SAP订单
     *
     * @param sapProductOrder SAP订单
     * @return 结果
     */
    @Override
    public int insertSapProductOrder(SapProductOrder sapProductOrder)
    {
        sapProductOrder.setCreateTime(DateUtils.getNowDate());
        return sapProductOrderMapper.insertSapProductOrder(sapProductOrder);
    }


    @Override
    public void insertAllSapProductOrder() {
        List<SapProductionOrder> sapProductionOrderList =  sapProductionOrderService.selectSapProductionOrderList(null);
        for (SapProductionOrder sapProductionOrder : sapProductionOrderList) {
            SapProductOrder sapProductOrder = new SapProductOrder();
            BeanUtils.copyProperties(sapProductionOrder,sapProductOrder);
            sapProductOrder.setId(UUID.randomUUID().toString());
            this.insertSapProductOrder(sapProductOrder);
        }

    }

    @Override
    public int deleteSapProductOrderByParam(SapProductOrder sapProductOrder) {
        return sapProductOrderMapper.deleteSapProductOrderByParam(null);
    }


}
